package com.yzmoney.wechat.action;

import com.yzmoney.common.constant.Constants;
import com.yzmoney.common.model.JsonResult;
import com.yzmoney.wechat.service.WeChatQRCodeService;
import net.sf.json.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * Created by DOVE on 2015/8/31.
 */
@Controller
@RequestMapping("/wechat")
public class WeChatQRCodeAction {
    private static Logger logger = Logger.getLogger(WeChatQRCodeAction.class);

    @Resource
    private WeChatQRCodeService weChatQRCodeService;

    /**
     * 获取生成的二维码信息
     *
     * @param qrInfo
     * @return
     */
    @RequestMapping("/getQRCodeInfo")
    @ResponseBody
    public JsonResult getQRCodeInfo(String qrInfo) {
        if (StringUtils.isNotEmpty(qrInfo)) {
            JsonResult jsonResult = new JsonResult();
            String result = weChatQRCodeService.getQRCodeInfo(qrInfo);
            JSONObject jsonObject = new JSONObject().fromObject(result);
            jsonResult.setData(jsonObject);
            return jsonResult;
        }
        JsonResult jsonResult=new JsonResult<>();
        jsonResult.setCode(Constants.CODE_FAILURE);
        return jsonResult;

    }

}
